package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ldc.common.model.RegisterInfoModel;
import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.common.net.Api2Request;
import com.ldc.common.utils.ToastUtils;
import com.ldc.wandroid.server.ApiServer;

public class RegisterViewModel extends ViewModelBase {

    private final ApiServer apiServer = Api2Request.getInstance().createServer(ApiServer.class);
    private final MutableLiveData<RegisterInfoModel> loginInfo = new MutableLiveData<>();

    public LiveData<RegisterInfoModel> getLoginInfo() {
        return loginInfo;
    }

    public void register(String userName, String passWord, String passWord2) {
        apiRequest(apiServer.register(userName, passWord, passWord2), (status, result, throwable) -> {
            if (status) {
                loginInfo.setValue(result.getData());
            } else {
                ToastUtils.showShort(result.getErrorMsg());
                loginInfo.setValue(null);
            }
        });
    }
}
